/**
 * Copyright © 2013 南京思创信息技术有限公司. *
 * 版权所有.
 *
 * 类名　　    : OnlineDetail
 * 功能概要    : 在线详细页面. * 做成日期    : 2013/06/13 wangxw
 */
package com.sevenit.nj.yrmtfish.online;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextPaint;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.webkit.DownloadListener;
import android.webkit.WebSettings;
import android.webkit.WebSettings.LayoutAlgorithm;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.sevenit.nj.yrmtfish.R;
import com.sevenit.nj.yrmtfish.common.AppManager;
import com.sevenit.nj.yrmtfish.common.FileBase;
import com.sevenit.nj.yrmtfish.common.ImageViewFitW;
import com.sevenit.nj.yrmtfish.common.ServerMaster;
import com.sevenit.nj.yrmtfish.common.StaticPara;
import com.sevenit.nj.yrmtfish.entity.OnlineData;
import com.sevenit.nj.yrmtfish.entity.ServerData;
import com.sevenit.nj.yrmtfish.login.Login;
import com.sevenit.nj.yrmtfish.common.Utils;

/**
 * 在线详细页面的类
 * @author wangxw
 * @version 1.0
 */
@SuppressLint("HandlerLeak") 
public class OnlineDetail extends Activity {
	
	//当面画面的名称
	private String _strPageName;
	
	//提示对话框.
	ProgressDialog _proDialog;
	
	//请求服务器方法
	private ServerMaster _server;
	
	///////定义画面专有消息////////
	// 秒杀商品.
	public final static int MSG_BUY_GOOD = 1;
	// 秒杀商品成功.
	public final static int MSG_BUY_GOOD_OK = 2;
	// 该商品已经秒杀完了.
	public final static int MSG_BUY_GOOD_EMPTY = 3;
	// 你已经秒杀过该商品.
	public final static int MSG_BUY_GOOD_AGAIN = 4;
	// 商品询问.
	public final static int MSG_ASK_GOOD = 5;
	// 商品询问成功.
	public final static int MSG_ASK_GOOD_OK = 6;
	
	//当前信息.
	OnlineData _infoObj;
	//当前显示的图片位置.
	int _currentImg;
	int[] _imgPage = new int[] { 
			R.id.img_page1, 
			R.id.img_page2,
			R.id.img_page3,
			R.id.img_page4
			};
	
	/**
	 * onCreate
	 */
	public void onCreate(Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);
		
		//自定义标题栏
		requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
		//设置画面布局
		this.setContentView(R.layout.online_detail);
		getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title);
		
		//添加该Activity到AppManager
		AppManager.addActivity(this);

		//初始化画面数据.
		initPageData(); 
		
		//获取前画面传过来的参数.
		getPara();
		
		//设置画面控件
		setControl();
		
		//线程查询数据.
		if(!Utils.isNull(_infoObj.getId())){
			// 显示进度
			_proDialog = ProgressDialog.show(OnlineDetail.this, "提示", "正在加载数据，请稍候...", true, true);
			(new Thread(new LoadThread(StaticPara.MSG_PAGE_LOADING))).start();
		}
	}

	/**
	 * 初始化画面数据.
	 */
	private void initPageData() {
		
		//当面画面的名称
		_strPageName = this.getClass().getName();
		
		//初始化全局对象
		_server = new ServerMaster(this, StaticPara.MemConf.AppServerIp, StaticPara.MemConf.AppServerPort);
		
		//初始化当前信息.
		_infoObj = new OnlineData();
		_currentImg = -1;
		
		//刷新画面线程.
		Thread showPageThread = new Thread(new ShowPageThread());
		showPageThread.start();
	}
	
	/**
	 * 获取前画面传过来的参数.
	 */
	private void getPara() {
		//获取传入的参数.
		Intent intentT = getIntent();
		_infoObj.setId(intentT.getStringExtra("info_id"));
		_infoObj.setName(intentT.getStringExtra("info_name"));
		
		if(Utils.isNull(_infoObj.getId())){
			//未查询到信息！
			Toast.makeText(OnlineDetail.this, R.string.msg_no_data, Toast.LENGTH_LONG).show();
		}
	}
	
	/**
	 * 设置画面控件
	 */
	private void setControl() {
		
		//设置标题文字
		TextView txtTitle = (TextView)findViewById(R.id.txt_title);
		txtTitle.setText(_infoObj.getName());
		//设置为粗体
		TextPaint paint = txtTitle.getPaint();
		paint.setFakeBoldText(true);
		
		//设置[返回]按钮按下效果
		ImageButton button = (ImageButton)findViewById(R.id.btn_back);
		button.setOnTouchListener(new ImageButton.OnTouchListener() {
			@Override
			public boolean onTouch(View arg0, MotionEvent arg1) {
				if (arg1.getAction() == MotionEvent.ACTION_DOWN) {
					arg0.setBackgroundResource(R.drawable.btn_back_p);
				} else if (arg1.getAction() == MotionEvent.ACTION_UP) {
					arg0.setBackgroundResource(R.drawable.btn_back);
				}
				return false;
			}
        });	
		//点击[返回]按钮的响应.
		button.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
	        	AppManager.closePage(OnlineDetail.class.getName());
			}
		});
		
		//初始化底部共通区域.
		setBtnBottom();
	}
	
	/**
	 * 初始化底部共通区域.
	 */
	private void setBtnBottom() {
		
		ImageViewFitW imgBtn;
		
		//设置[首页]按钮按下效果
		imgBtn = (ImageViewFitW)findViewById(R.id.btn_tail_shouye);
		imgBtn.setOnTouchListener(new ImageViewFitW.OnTouchListener() {
			@Override
			public boolean onTouch(View arg0, MotionEvent arg1) {
				if (arg1.getAction() == MotionEvent.ACTION_DOWN) {
					((ImageViewFitW)arg0).setImageResource(R.drawable.btn_shouye_p);
				} else if (arg1.getAction() == MotionEvent.ACTION_UP) {
					((ImageViewFitW)arg0).setImageResource(R.drawable.btn_shouye);
				}
				return false;
			}
        });	
		//点击[首页]按钮的响应.
		imgBtn.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				AppManager.goMenu();
				//去除画面跳转时的动画效果
				overridePendingTransition(0, 0);
			}
		});
		
		//设置[车况]按钮按下效果
		imgBtn = (ImageViewFitW)findViewById(R.id.btn_tail_chekuang);
		imgBtn.setOnTouchListener(new ImageViewFitW.OnTouchListener() {
			@Override
			public boolean onTouch(View arg0, MotionEvent arg1) {
				if (arg1.getAction() == MotionEvent.ACTION_DOWN) {
					((ImageViewFitW)arg0).setImageResource(R.drawable.btn_chekuang_p);
				} else if (arg1.getAction() == MotionEvent.ACTION_UP) {
					((ImageViewFitW)arg0).setImageResource(R.drawable.btn_chekuang);
				}
				return false;
			}
        });	
		//点击[车况]按钮的响应.
		imgBtn.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				if(!StaticPara.isLogin()){
					Toast.makeText(OnlineDetail.this, R.string.msg_err_not_login, Toast.LENGTH_SHORT).show();
				}else{
					//Intent intent = new Intent();
					//intent.setClass(OnlineDetail.this, CarConditionThis.class);
					//startActivity(intent);
					//去除画面跳转时的动画效果
					overridePendingTransition(0, 0);
					AppManager.closePage(OnlineList.class.getName());
					AppManager.closePage(OnlineDetail.class.getName());
				}
			}
		});

		//设置[VIP]或[登录]按钮.
		setBtnVip();

		//设置[设置]按钮按下效果
		imgBtn = (ImageViewFitW)findViewById(R.id.btn_tail_shezhi);
		imgBtn.setOnTouchListener(new ImageViewFitW.OnTouchListener() {
			@Override
			public boolean onTouch(View arg0, MotionEvent arg1) {
				if (arg1.getAction() == MotionEvent.ACTION_DOWN) {
					((ImageViewFitW)arg0).setImageResource(R.drawable.btn_shezhi_p);
				} else if (arg1.getAction() == MotionEvent.ACTION_UP) {
					((ImageViewFitW)arg0).setImageResource(R.drawable.btn_shezhi);
				}
				return false;
			}
        });	
		//点击[设置]按钮的响应.
		imgBtn.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				//Intent intent = new Intent();
				//intent.setClass(OnlineDetail.this, Setting.class);
				//startActivity(intent);
				//去除画面跳转时的动画效果
				overridePendingTransition(0, 0);
				AppManager.closePage(OnlineList.class.getName());
				AppManager.closePage(OnlineDetail.class.getName());
			}
		});

		//设置[更多]按钮按下效果
		imgBtn = (ImageViewFitW)findViewById(R.id.btn_tail_gengduo);
		imgBtn.setOnTouchListener(new ImageViewFitW.OnTouchListener() {
			@Override
			public boolean onTouch(View arg0, MotionEvent arg1) {
				if (arg1.getAction() == MotionEvent.ACTION_DOWN) {
					((ImageViewFitW)arg0).setImageResource(R.drawable.btn_gengduo_p);
				} else if (arg1.getAction() == MotionEvent.ACTION_UP) {
					((ImageViewFitW)arg0).setImageResource(R.drawable.btn_gengduo);
				}
				return false;
			}
        });	
		//点击[更多]按钮的响应.
		imgBtn.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Toast.makeText(OnlineDetail.this, R.string.msg_btn_more, Toast.LENGTH_SHORT).show();
				//AppManager.closePage(OnlineList.class.getName());
				//AppManager.closePage(OnlineDetail.class.getName());
			}
		});
	}
	
	/**
	 * 设置[登录]或[VIP]按钮.
	 */
	private void setBtnVip() {
		
		ImageViewFitW imgBtn;
		
		if(!StaticPara.isLogin()){
			//设置[登陆]按钮按下效果
			imgBtn = (ImageViewFitW)findViewById(R.id.btn_tail_denglu);
			imgBtn.setImageResource(R.drawable.btn_denglu);
			imgBtn.setOnTouchListener(new ImageViewFitW.OnTouchListener() {
				@Override
				public boolean onTouch(View arg0, MotionEvent arg1) {
					if (arg1.getAction() == MotionEvent.ACTION_DOWN) {
						((ImageViewFitW)arg0).setImageResource(R.drawable.btn_denglu_p);
					} else if (arg1.getAction() == MotionEvent.ACTION_UP) {
						((ImageViewFitW)arg0).setImageResource(R.drawable.btn_denglu);
					}
					return false;
				}
		    });	
			//点击[登陆]按钮的响应.
			imgBtn.setOnClickListener(new OnClickListener() {
				public void onClick(View v) {
					Intent intent = new Intent();
					intent.setClass(OnlineDetail.this, Login.class);
					startActivity(intent);
					AppManager.closePage(OnlineList.class.getName());
					AppManager.closePage(OnlineDetail.class.getName());
				}
			});
		}else{
			//设置[VIP]按钮按下效果
			imgBtn = (ImageViewFitW)findViewById(R.id.btn_tail_denglu);
			imgBtn.setImageResource(R.drawable.btn_vip);
			imgBtn.setOnTouchListener(new ImageViewFitW.OnTouchListener() {
				@Override
				public boolean onTouch(View arg0, MotionEvent arg1) {
					if (arg1.getAction() == MotionEvent.ACTION_DOWN) {
						((ImageViewFitW)arg0).setImageResource(R.drawable.btn_vip_p);
					} else if (arg1.getAction() == MotionEvent.ACTION_UP) {
						((ImageViewFitW)arg0).setImageResource(R.drawable.btn_vip);
					}
					return false;
				}
		    });	
			//点击[VIP]按钮的响应.
			imgBtn.setOnClickListener(new OnClickListener() {
				public void onClick(View v) {
					//Intent intent = new Intent();
					//intent.setClass(OnlineDetail.this, CarVipDetail.class);
					//startActivity(intent);
					//去除画面跳转时的动画效果
					overridePendingTransition(0, 0);
					AppManager.closePage(OnlineList.class.getName());
					AppManager.closePage(OnlineDetail.class.getName());
				}
			});
		}
	}

	/**
	 * 监听手机硬件上的返回等按钮
	 */
	@Override 
    public boolean onKeyDown(int keyCode, KeyEvent event) { 
        if (keyCode == KeyEvent.KEYCODE_BACK &&	event.getRepeatCount() == 0) {
        	AppManager.closePage(OnlineDetail.class.getName());
            return false; 
        }
        return false; 
    }

	/**
	 * 显示画面的数据.
	 */
	private void showData(){
		
		//标题.
		TextView txtTitle = (TextView)findViewById(R.id.txt_title);
		txtTitle.setText(_infoObj.getName());
		
		//详细.
		WebView wView = (WebView) this.findViewById(R.id.web_detail);
		//图片自适应大小
		WebSettings webSettings= wView.getSettings(); 
		webSettings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN); 
		//设置内容.
		if(Utils.isNull(_infoObj.getDetail())){
			wView.loadDataWithBaseURL(null,"还未添加内容!", "text/html", "UTF-8",null);
		}else{
			wView.loadDataWithBaseURL(null,_infoObj.getDetail(), "text/html", "UTF-8",null);
		}
		// 如果页面中链接，如果希望点击链接继续在当前browser中响应,
		// 而不是新开Android的系统browser中响应该链接，必须覆盖webview的WebViewClient对象.
		wView.setWebViewClient(new WebViewClient() {
			public boolean shouldOverrideUrlLoading(WebView view, String url){
				//  重写此方法表明点击网页里面的链接还是在当前的webview里跳转，不跳到浏览器那边.
				if(!Utils.isNull(url)){
					//下载.
					if(url.toLowerCase().endsWith(".pdf") || 
						url.toLowerCase().endsWith(".zip") || 
						url.toLowerCase().endsWith(".rar")){
						Uri uri = Uri.parse(url);  
						Intent intent = new Intent(Intent.ACTION_VIEW, uri);  
						startActivity(intent);  
					}
					//网页.
					else {
						Intent intent = new Intent();
						intent.setClass(OnlineDetail.this, WebWindow.class);
						intent.putExtra("url", url);
						startActivity(intent);
					}
				}
				return true;
			}
		});
		//监听网页中的下载链接--不起作用.
		wView.setDownloadListener(new DownloadListener() {  

			@Override  
			public void onDownloadStart(String url, 
										String userAgent, 
										String contentDisposition, 
										String mimetype,
										long contentLength) {  
				//Uri uri = Uri.parse(url);  
				//Intent intent = new Intent(Intent.ACTION_VIEW, uri);  
				//startActivity(intent);  
			}
		} );
		
		//按钮.
		//信息类型（0或NULL：商品、1：4S店、2：专家技师、3：保养知识，100以下保留）
		ImageButton button = (ImageButton)findViewById(R.id.btn_detail);
		if(StaticPara.isLogin() && _infoObj.isMiaosha()){//秒杀
			//设置[立即抢购]按钮按下效果
			button.setVisibility(View.VISIBLE);
			button.setBackgroundResource(R.drawable.btn_ljqg);
			button.setOnTouchListener(new ImageButton.OnTouchListener() {
				@Override
				public boolean onTouch(View arg0, MotionEvent arg1) {
					if (arg1.getAction() == MotionEvent.ACTION_DOWN) {
						arg0.setBackgroundResource(R.drawable.btn_ljqg_p);
					} else if (arg1.getAction() == MotionEvent.ACTION_UP) {
						arg0.setBackgroundResource(R.drawable.btn_ljqg);
					}
					return false;
				}
	        });	
			//点击[立即抢购]按钮的响应.
			button.setOnClickListener(new OnClickListener() {
				public void onClick(View v) {
		        	if(!StaticPara.isLogin()){
		        		Toast.makeText(OnlineDetail.this, R.string.msg_err_not_login, Toast.LENGTH_SHORT).show();
		        		return;
		        	}
		        	// 显示进度
					_proDialog = ProgressDialog.show(OnlineDetail.this, "提示", "正在抢购，请稍候...", true, true);
					(new Thread(new LoadThread(MSG_BUY_GOOD))).start();
				}
			});
		} else if(StaticPara.isLogin() && 
				(Utils.isNull(_infoObj.getInfoType()) || "0".equals(_infoObj.getInfoType()))){//商品
			//设置[询问一下]按钮按下效果
			button.setVisibility(View.VISIBLE);
			button.setBackgroundResource(R.drawable.btn_xwyx);
			button.setOnTouchListener(new ImageButton.OnTouchListener() {
				@Override
				public boolean onTouch(View arg0, MotionEvent arg1) {
					if (arg1.getAction() == MotionEvent.ACTION_DOWN) {
						arg0.setBackgroundResource(R.drawable.btn_xwyx_p);
					} else if (arg1.getAction() == MotionEvent.ACTION_UP) {
						arg0.setBackgroundResource(R.drawable.btn_xwyx);
					}
					return false;
				}
	        });	
			//点击[询问一下]按钮的响应.
			button.setOnClickListener(new OnClickListener() {
				public void onClick(View v) {
					if(!StaticPara.isLogin()){
		        		Toast.makeText(OnlineDetail.this, R.string.msg_err_not_login, Toast.LENGTH_SHORT).show();
		        		return;
		        	}
					// 显示进度
					_proDialog = ProgressDialog.show(OnlineDetail.this, "提示", "正在提交询问，请稍候...", true, true);
					(new Thread(new LoadThread(MSG_ASK_GOOD))).start();
				}
			});
		} else if(!Utils.isNull(_infoObj.getTelNum())){//其他
			//设置[联系我]按钮按下效果
			button.setVisibility(View.VISIBLE);
			button.setBackgroundResource(R.drawable.btn_lxw);
			button.setOnTouchListener(new ImageButton.OnTouchListener() {
				@Override
				public boolean onTouch(View arg0, MotionEvent arg1) {
					if (arg1.getAction() == MotionEvent.ACTION_DOWN) {
						arg0.setBackgroundResource(R.drawable.btn_lxw_p);
					} else if (arg1.getAction() == MotionEvent.ACTION_UP) {
						arg0.setBackgroundResource(R.drawable.btn_lxw);
					}
					return false;
				}
	        });	
			//点击[联系我]按钮的响应.
			button.setOnClickListener(new OnClickListener() {
				public void onClick(View v) {
					//启动拨打电话画面.
					Intent myIntentDial = new Intent( Intent.ACTION_CALL,Uri.parse("tel:" + _infoObj.getTelNum()));
					startActivity(myIntentDial);
				}
			});
		}
		
		//第一次显示.
		int iCount = _infoObj.getImgLstPathHttp().size();
		for(int i = 0; i < _imgPage.length; i++){
			if(iCount >= (i + 1)){
				((ImageView)findViewById(_imgPage[i])).setVisibility(View.VISIBLE);
			}
		}
	}
		
	/**
	 * 播放图片.
	 */
	private void flashImg(){
			
		//图片还未下载好.
		if(_infoObj.getImageLstObj().size() <= 0){
			return;
		}
		
		if(_currentImg >= (_infoObj.getImageLstObj().size() - 1)){
			_currentImg = -1;
		}
		_currentImg++;
		
		//图片.
		boolean bShowImgOk = false;
		ImageView img = (ImageView)findViewById(R.id.img_top1);
		Drawable di = (Drawable)_infoObj.getImageLstObj().get(_currentImg);
		if(di != null){
			img.setImageDrawable(di);
    		bShowImgOk = true;
    	}
    	//资源图片.
    	if(!bShowImgOk && _infoObj.getImgId() > 0){
    		img.setImageResource(_infoObj.getImgId());
    	}
    	
    	if(_currentImg == 0){
    		((ImageView)findViewById(_imgPage[_infoObj.getImgLstPathHttp().size() - 1])).setImageResource(R.drawable.menu_point);
    	}else{
    		((ImageView)findViewById(_imgPage[_currentImg - 1])).setImageResource(R.drawable.menu_point);
    	}
    	((ImageView)findViewById(_imgPage[_currentImg])).setImageResource(R.drawable.menu_point_p);

	}
	
	/**
	 * 刷新画面线程.
	 * @author wangxw
	 */
	class ShowPageThread implements Runnable {
		public void run() {
			try{
				while(true){
					Thread.sleep(5000);
				
					sendMsg(StaticPara.MSG_PAGE_REFRESH);
				}
				
			}catch(Exception e){
			}
		}
	}
	
	/**
	 * 新线程查询数据.
	 * @author wangxw
	 */
	class LoadThread implements Runnable {

		private int _iWorkType = 0;
		
		/**
		 * 构造函数
		 * 
		 * @param iDoType 处理类型
		 */
		public LoadThread(int iDoType){
			_iWorkType = iDoType;
		}
		
		/**
		 * 
		 */
		public void run() {
			
			//装载画面.
			if(_iWorkType == StaticPara.MSG_PAGE_LOADING){
				//查询数据.
				doSearch();
				
				//下载图片
				loadImg();
			}
			//购买商品.
			else if(_iWorkType == MSG_BUY_GOOD){
				doBuyGoods();
			} 
			//商品询问.
			else if(_iWorkType == MSG_ASK_GOOD){
				doAskGoods();
			} 
		}
		
		/**
		 * 查询数据.
		 */
		public void doSearch() {
			Map<String, String> hMap = new HashMap<String, String>();
			hMap.put("CarNumber", StaticPara.MemConf.CarNo);
			hMap.put("ID", _infoObj.getId());
			hMap.put("Type", "1");
			ServerData sd = _server.doRequest("Get4SList",hMap);

			if (sd.getStatus() == -1) {
				//当前网络不可用.
				sendMsg(StaticPara.MSG_ERR_NET);
			} else if (sd.getStatus() == -2) {
				//不能连接服务器，请稍候再试！
				sendMsg(StaticPara.MSG_ERR_SERVER);
			} else if (sd.getStatus() == -99){
				//未知的错误.
				sendMsg(StaticPara.MSG_ERR_UNKNOW);
			} else if (sd.getStatus() == 1){
				
				//未查询到数据.
				if(sd.count() <= 1){
					sendMsg(StaticPara.MSG_ERR_NODATA);
					return;
				}
				
				//返回值是否正常.
				sd.first();
				if(!"00".equals(sd.getString("ReturnCode"))){
					//未知的错误.
					sendMsg(StaticPara.MSG_ERR_UNKNOW);
					return;
				}
				
				//设置数据.
				sd.next();
				//ID
				_infoObj.setId(sd.getString("Id"));
				//名称
				_infoObj.setName(sd.getString("Name"));
				//详细
				_infoObj.setDetail(sd.getString("Content"));
				//图片
				String strTemp;
				_infoObj.setImgId(R.drawable.online_pic);//默认图片
				strTemp = sd.getString("Sequence");
				strTemp = sd.getString("PicAdd");
				if(!Utils.isNull(strTemp)){
					List<String> lsImg = new ArrayList<String>();
					String[] strPics = strTemp.split("\\|");
					for(int i = 0;i<strPics.length;i++){
						if(!Utils.isNull(strPics[i])){
							lsImg.add(strPics[i]);
						}
					}
					_infoObj.setImgLstPathHttp(lsImg);
				}
				//信息类型
				_infoObj.setInfoType(sd.getString("InfoType"));
				//电话号码
				_infoObj.setTelNum(sd.getString("GoodsTel"));
				//是否是秒杀
				strTemp = sd.getString("IsMiaosha");
				_infoObj.setMiaosha("1".equals(strTemp));
				
				//先显示画面数据.
				sendMsg(StaticPara.MSG_PAGE_SHOW_DATA);
			}
		}

		/**
		 * 下载图片
		 */
		private void loadImg() {
			
			List<String> lsImgHttp = _infoObj.getImgLstPathHttp();
			
			//获取图片
			FileBase fb = new FileBase();
			String strImgHttp;
			for(int i = 0;i < lsImgHttp.size();i++){

				strImgHttp = "";
				
				//获取网络图片地址.
				strImgHttp = lsImgHttp.get(i);
				
				//如果没有获取到.
				if(Utils.isNull(strImgHttp)){
					continue;
				}
				//获取网络图片.
				strImgHttp = StaticPara.getFileServer() + strImgHttp;
				Drawable dr = fb.getImgFromUrl(strImgHttp, true);
				if(dr == null){
					continue;
				}
				List<Drawable> lsT = _infoObj.getImageLstObj();
				if(lsT.size() < 4){
					lsT.add(dr);
				}
			}
			//刷新画面数据.
			sendMsg(StaticPara.MSG_PAGE_REFRESH);
		}
		
		/**
		 * 购买商品.
		 */
		public void doBuyGoods() {
			Map<String, String> hMap = new HashMap<String, String>();
			hMap.put("CarNumber", StaticPara.MemConf.CarNo);
			hMap.put("OrderID", "2");
			hMap.put("GoodsId", _infoObj.getId());
			ServerData sd = _server.doRequest("SubmittedGoods",hMap);

			if (sd.getStatus() == -1) {
				//当前网络不可用.
				sendMsg(StaticPara.MSG_ERR_NET);
			} else if (sd.getStatus() == -2) {
				//不能连接服务器，请稍候再试！
				sendMsg(StaticPara.MSG_ERR_SERVER);
			} else if (sd.getStatus() == -99){
				//未知的错误.
				sendMsg(StaticPara.MSG_ERR_UNKNOW);
			} else if (sd.getStatus() == 1){
				
				//未查询到数据.
				if(sd.count() <= 0){
					sendMsg(StaticPara.MSG_ERR_UNKNOW);
					return;
				}
				
				//返回值是否正常.
				sd.first();
				//秒杀成功.
				if("03".equals(sd.getString("ReturnCode"))){
					sendMsg(MSG_BUY_GOOD_OK);
				}
				//该商品已经秒杀完了.
				else if("04".equals(sd.getString("ReturnCode"))){
					sendMsg(MSG_BUY_GOOD_EMPTY);
				}
				//你已经秒杀过该商品.
				else if("05".equals(sd.getString("ReturnCode"))){
					sendMsg(MSG_BUY_GOOD_AGAIN);
				} else{
					sendMsg(StaticPara.MSG_ERR_UNKNOW);
				}
			}
		}
		
		/**
		 * 商品询问.
		 */
		public void doAskGoods() {
			Map<String, String> hMap = new HashMap<String, String>();
			hMap.put("CarNumber", StaticPara.MemConf.CarNo);
			hMap.put("OrderID", "0");
			hMap.put("GoodsId", _infoObj.getId());
			ServerData sd = _server.doRequest("SubmittedGoods",hMap);

			if (sd.getStatus() == -1) {
				//当前网络不可用.
				sendMsg(StaticPara.MSG_ERR_NET);
			} else if (sd.getStatus() == -2) {
				//不能连接服务器，请稍候再试！
				sendMsg(StaticPara.MSG_ERR_SERVER);
			} else if (sd.getStatus() == -99){
				//未知的错误.
				sendMsg(StaticPara.MSG_ERR_UNKNOW);
			} else if (sd.getStatus() == 1){
				
				//未查询到数据.
				if(sd.count() <= 0){
					sendMsg(StaticPara.MSG_ERR_UNKNOW);
					return;
				}
				
				sd.first();
				//商品询问成功.
				if("00".equals(sd.getString("ReturnCode"))){
					sendMsg(MSG_ASK_GOOD_OK);
				} else{
					sendMsg(StaticPara.MSG_ERR_UNKNOW);
				}
			}
		}
	}

	/**
	 * 向界面发送消息.
	 * UI显示动作不能在线程里做.
	 */
	private void sendMsg(int Msg){
		Message message = new Message();
		Bundle bundle = new Bundle();
		bundle.putInt(_strPageName, Msg);
		message.setData(bundle);
		myHandler.sendMessage(message);
	}
		
	//主线程消息处理.
	Handler myHandler = new Handler() {
		public void handleMessage(Message msg) {
			int iMsg = msg.getData().getInt(_strPageName);
			switch (iMsg) {
			
			case StaticPara.MSG_ERR_NET:
				if (_proDialog != null) {
					_proDialog.dismiss();
				}
				Toast.makeText(OnlineDetail.this, R.string.msg_net_error, Toast.LENGTH_LONG).show();
				break;
			case StaticPara.MSG_ERR_SERVER:
				if (_proDialog != null) {
					_proDialog.dismiss();
				}
				Toast.makeText(OnlineDetail.this, R.string.msg_server_error, Toast.LENGTH_LONG).show();
				break;
			case StaticPara.MSG_ERR_UNKNOW:
				if (_proDialog != null) {
					_proDialog.dismiss();
				}
				Toast.makeText(OnlineDetail.this, R.string.msg_unknown_error, Toast.LENGTH_LONG).show();
				break;
			case StaticPara.MSG_ERR_NODATA:
				if (_proDialog != null) {
					_proDialog.dismiss();
				}
				Toast.makeText(OnlineDetail.this, R.string.msg_no_data, Toast.LENGTH_LONG).show();
				break;
			case StaticPara.MSG_PAGE_SHOW_DATA://显示数据.
				if (_proDialog != null) {
					_proDialog.dismiss();
				}
				showData();
				break;
			case StaticPara.MSG_PAGE_REFRESH://播放图片.
				flashImg();
				break;
			case MSG_BUY_GOOD_OK://秒杀商品成功.
				if (_proDialog != null) {
					_proDialog.dismiss();
				}
				Toast.makeText(OnlineDetail.this, R.string.msg_buy_goods_ok, Toast.LENGTH_LONG).show();
				break;
			case MSG_BUY_GOOD_EMPTY://该商品已经秒杀完了.
				if (_proDialog != null) {
					_proDialog.dismiss();
				}
				Toast.makeText(OnlineDetail.this, R.string.msg_buy_goods_empty, Toast.LENGTH_LONG).show();
				break;
			case MSG_BUY_GOOD_AGAIN://你已经秒杀过该商品.
				if (_proDialog != null) {
					_proDialog.dismiss();
				}
				Toast.makeText(OnlineDetail.this, R.string.msg_buy_goods_again, Toast.LENGTH_LONG).show();
				break;
			case MSG_ASK_GOOD_OK://商品询问成功.
				if (_proDialog != null) {
					_proDialog.dismiss();
				}
				Toast.makeText(OnlineDetail.this, R.string.msg_ask_goods_ok, Toast.LENGTH_LONG).show();
				break;
			default:
				if (_proDialog != null) {
					_proDialog.dismiss();
				}
			}
			
			super.handleMessage(msg);
		}
	};
}
